package com.anrongtec.zcpt.manager;

import java.util.List;

import android.content.Context;
import android.view.ViewGroup;

import com.anrongtec.zcpt.R;
import com.anrongtec.zcpt.stickyheadersrecyclerview.StickyRecyclerHeadersAdapter;
import com.lzy.okhttpserver.download.DownloadInfo;
import com.lzy.okhttpserver.download.DownloadManager;
import com.zhy.adapter.recyclerview.MultiItemTypeAdapter;
import com.zhy.adapter.recyclerview.base.ViewHolder;

public class AppDownManageAdapter extends MultiItemTypeAdapter<DownloadInfo>
		implements StickyRecyclerHeadersAdapter<ViewHolder> {
	public static final int STATUS_DOWNLOADING = 1;
	public static final int STATUS_DOWNLOADED = 2;

	public AppDownManageAdapter(Context context, List<DownloadInfo> datas) {
		super(context, datas);
	}

	@Override
	public long getHeaderId(int position) {
		DownloadInfo info = mDatas.get(position);
		if (info.getState() == DownloadManager.FINISH) {
			return STATUS_DOWNLOADED;
		}
		return STATUS_DOWNLOADING;
	}

	@Override
	public int getItemViewType(int position) {
		DownloadInfo info = mDatas.get(position);
		if (info.getState() == DownloadManager.FINISH) {
			return STATUS_DOWNLOADED;
		}
		return STATUS_DOWNLOADING;
	}

	@Override
	public void onBindHeaderViewHolder(ViewHolder holder, int position) {
		int viewType = getItemViewType(position);
		if (viewType == STATUS_DOWNLOADED) {
			holder.setText(R.id.tv_item_header_down_manager_name, "已下载");
			return;
		}
		holder.setText(R.id.tv_item_header_down_manager_name, "下载中");
	}

	@Override
	public ViewHolder onCreateHeaderViewHolder(ViewGroup parent) {
		ViewHolder holder = ViewHolder.createViewHolder(mContext, parent,
				R.layout.item_header_down_manager);
		return holder;
	}

	// private class HeaderViewHolder extends ViewHolder {
	//
	// public HeaderViewHolder(Context context, View itemView) {
	// super(context, itemView);
	// }
	//
	// }

	// @Override
	// public int getItemCount() {
	// // TODO Auto-generated method stub
	// return mDatas.size();
	// }
}
